#include "StaticCompose.h"

StaticCompose::StaticCompose()
{

}

StaticCompose::~StaticCompose()
{
	ComposeInfoStaticMap::iterator iter = mComposeInfoMap.begin();
	while(iter != mComposeInfoMap.end())
	{
		delete (iter->second);
		iter++;
	}
	mComposeInfoMap.clear();
}

void StaticCompose::parse()
{
	const char* path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("config/Compose.xml");

	xmlDocPtr equipDoc = xmlReadFile(path, "utf-8", XML_PARSER_EOF);
	if(NULL == equipDoc)
		CCLOG("Dungeons xml parse failed!");

	xmlNodePtr equipRootNode = xmlDocGetRootElement(equipDoc);
	if(NULL == equipRootNode)
		CCLOG("Dungeons xml root null!");

	xmlNodePtr equipChildNode = equipRootNode->children->next;

	xmlNodePtr curNode = equipChildNode;
	while(NULL != curNode)
	{
		if (curNode->type == XML_COMMENT_NODE)break;
		ComposeInfoStatic* composeInfoStatic = new ComposeInfoStatic();
		composeInfoStatic->mItemID = attriToInt(curNode, "itemID");
		xmlNodePtr subNode = curNode->next;
		while(subNode)
		{
			ComposeItemStatic* composeItemStatic = new ComposeItemStatic();
			composeItemStatic->mItemID = attriToInt(curNode, "itemID");
			composeItemStatic->mItemCount = attriToInt(curNode, "itemCount");
			composeInfoStatic->mComposeItemList.push_back(composeItemStatic);
		}
		mComposeInfoMap[composeInfoStatic->mItemID] = composeInfoStatic;
		curNode = curNode->prev;
	}

	xmlFreeDoc(equipDoc);
}

ComposeInfoStatic* StaticCompose::getComposeInfo( int itemID )
{
	return mComposeInfoMap[itemID];
}

